import request from '@/router/axios';
import {downloadExcel} from '@/router/axios';
import {formatCondition} from '@/util/util';
import {setStore, getStore} from '@/util/store'

//单条查询
export const querySysUserInfo = (params) => {
  params.head.transCode = 'querySysUserInfo';
  return request({
    url: '/platform/sysUserInfo/querySysUserInfo',
    method: 'post',
    data: params
  })
}
//多条列表查询，支持条件查询
export const querySysUserInfoListPage = (params) => {
  params.head.transCode = 'querySysUserInfoListPage';
  return request({
    url: '/platform/sysUserInfo/querySysUserInfoListPage',
    method: 'post',
    data: params
  })
}
//新增单条记录
export const saveSysUserInfo = (params) => {
  params.head.transCode = 'saveSysUserInfo';
  return request({
    url: '/platform/sysUserInfo/saveSysUserInfo',
    method: 'post',
    data: params
  })
}
//新增多条记录
export const saveSysUserInfoList = (params) => {
  params.head.transCode = 'saveSysUserInfoList';
  return request({
    url: '/platform/sysUserInfo/saveSysUserInfoList',
    method: 'post',
    data: params
  })
}
//新增或修改单条记录
export const saveOrUpdateSysUserInfo = (params) => {
  params.head.transCode = 'saveOrUpdateSysUserInfo';
  return request({
    url: '/platform/sysUserInfo/saveOrUpdateSysUserInfo',
    method: 'post',
    data: params
  })
}


//新增或修改单条记录
export const saveOrUpdateSysUserInfoList = (params) => {
  params.head.transCode = 'saveOrUpdateSysUserInfoList';
  return request({
    url: '/platform/sysUserInfo/saveOrUpdateSysUserInfoList',
    method: 'post',
    data: params
  })
}

//修改单条记录
export const updateSysUserInfo = (params) => {
  params.head.transCode = 'updateSysUserInfo';
  return request({
    url: '/platform/sysUserInfo/updateSysUserInfo',
    method: 'post',
    data: params
  })
}
//创建项目Admin用户
export const createProjectAdminUser = (params) => {
  params.head.transCode = 'createProjectAdminUser';
  return request({
    url: '/platform/sysUserInfo/createProjectAdminUser',
    method: 'post',
    data: params
  })
}
//创建租户Admin用户
export const createAdminUser = (params) => {
  params.head.transCode = 'createAdminUser';
  return request({
    url: '/platform/sysUserInfo/createAdminUser',
    method: 'post',
    data: params
  })
}
//重置管理员密码
export const restAdminPassword = (params) => {
  params.head.transCode = 'restAdminPassword';
  return request({
    url: '/platform/sysUserInfo/restAdminPassword',
    method: 'post',
    data: params
  })
}
//重置用户密码
export const restUserPassword = (params) => {
  params.head.transCode = 'restUserPassword';
  return request({
    url: '/platform/sysUserInfo/restUserPassword',
    method: 'post',
    data: params
  })
}

//删除单条记录
export const deleteSysUserInfo = (params) => {
  params.head.transCode = 'deleteSysUserInfo';
  return request({
    url: '/platform/sysUserInfo/deleteSysUserInfo',
    method: 'post',
    data: params
  })
}

//删除多条记录
export const deleteSysUserInfoList = (params) => {
  params.head.transCode = 'deleteSysUserInfoList';
  return request({
    url: '/platform/sysUserInfo/deleteSysUserInfoList',
    method: 'post',
    data: params
  })
}
//导出excel
export const exportSysUserInfoExcel = (params) => {
  downloadExcel({
    url: '/platform/sysUserInfo/excelDownload/exportSysUserInfoExcel',
    method: 'get',
    data: 
    {
      tenantId: params.head.tenantId,
      orders:'',
      condition: formatCondition(params.body.sqlCondition)
    }
  })
}

//用户登录
export const loginByUsername = (params) => {
  return request({
    url: '/dooleenApi/oauth/token',
    method: 'post',
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    meta: {
      isToken: true
    },
    params: {
      grant_type: 'password',
      ...params,
      scope: 'all'
    }
  })
}

//刷新token
export const refreshToken = (params) => {
  return request({
    url: '/dooleenApi/oauth/token',
    method: 'post',
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    meta: {
      isToken: true
    },
    params: {
      grant_type: 'refresh_token',
      refresh_token: getStore({name: 'refreshToken'})
    }
  })
}

//退出删除token
export const logOut = (accessToken, refreshToken) => {
  return request({
    url: '/dooleenApi/authentication/removeToken',
    method: 'post',
    data: {
      accessToken: accessToken,
      refreshToken: refreshToken
    }
  })
}

